package com.hmdp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.dto.Result;
import com.hmdp.entity.ShopComments;
import com.hmdp.mapper.ShopCommentsMapper;
import com.hmdp.service.IShopCommentsService;
import com.hmdp.utils.UserHolder;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 *
 */
@Service
public class ShopCommentsServiceImpl extends ServiceImpl<ShopCommentsMapper, ShopComments> implements IShopCommentsService {
    @Override
    public Result saveShopComment(ShopComments sc) {
        // 1.获取登录用户
        Long userId = UserHolder.getUser().getId();
        sc.setUserId(userId);
        // 2.创建时间
        sc.setCreateTime(LocalDateTime.now());
        boolean flag = this.save(sc);
        if(flag){
            return Result.ok(sc);
        }
        return Result.fail("发表评论失败");
    }
}
